﻿using ManagedTFRecordLibrary;
using Newtonsoft.Json;
using System;
using System.IO;
using System.Text;

namespace TestApp
{
    class Program
    {
        static void Main(string[] args)
        {
            TestRead2();
            Console.WriteLine("Hello World!");
        }

        static void TestWrite()
        {
            using (var fs = new FileStream(@"C:\Data\TFRecordTest\test.tfrecords", FileMode.CreateNew))
            {
                using (var writer = new TFRecordWriter(fs, true))
                {
                    byte[] hello = Encoding.ASCII.GetBytes("Hello");
                    writer.Write(hello, 0, hello.Length);
                    writer.Write(hello, 0, hello.Length);
                    writer.Write(hello, 0, hello.Length);
                }
            }
        }

        static void TestRead()
        {
            using (var fs = new FileStream(@"C:\Data\TFRecordTest\pyout.tfrecords", FileMode.Open))
            {
                using (var reader =new TFRecordReader(fs, true))
                {
                    while (reader.TryGoForward())
                    {
                        byte[] buffer = new byte[reader.CurrentLength];
                        if (reader.TryReadCurrent(buffer))
                        {
                            Console.WriteLine("Item read.");
                        }
                    }
                }
            }
        }
        static void TestRead2()
        {
            using (var fs = new FileStream(@"C:\Data\TFRecordTest\pyout2.tfrecords", FileMode.Open))
            {
                using (var reader = new TFRecordReader(fs, true))
                {
                    while (reader.TryGoForward())
                    {
                        var example = reader.TryParseExample();
                        Console.WriteLine(JsonConvert.SerializeObject(example));
                    }
                }
            }
        }
    }
}
